package com.baic.ibase.controller.api.v1;


import com.baic.ibase.models.dao.UsersRoles;
import com.baic.ibase.models.req.common.ApiResponse;
import com.baic.ibase.service.roles.UsersRolesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequestMapping("/api/v1/usersRoles")
@RestController
public class UsersRolesController {

    @Autowired
    private UsersRolesService usersRolesService;

    /**
     * @api {GET} /api/v1/usersRoles/ListUsersRoles ListUsersRoles()
     * @apiVersion 1.0.0
     * @apiGroup UsersRolesController
     * @apiName ListUsersRoles()
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Array} data
     * @apiSuccess (响应结果) {Number} data.id
     * @apiSuccess (响应结果) {Number} data.usersId 用户id
     * @apiSuccess (响应结果) {Number} data.rolesId 角色id
     * @apiSuccess (响应结果) {Object} data.createdTime 创建时间
     * @apiSuccess (响应结果) {Object} data.updatedTime 更新时间
     * @apiSuccess (响应结果) {Number} data.createdUserId 创建人
     * @apiSuccess (响应结果) {Number} data.updatedUserId 更新人
     * @apiSuccessExample 响应结果示例
     * {"traceId":"HFSILs07","code":8660,"data":[{"createdUserId":8298,"usersId":2146,"rolesId":7012,"id":2416,"updatedUserId":9372}],"success":false,"message":"TZ","errors":"K13vAIJSxs"}
     */
    @RequestMapping("/ListUsersRoles")
    public ApiResponse<List<UsersRoles>> ListUsersRoles()
    {
        return ApiResponse.ok(usersRolesService.list());
    }

    /**
     * @api {GET} /api/v1/usersRoles/AddUsersRoles AddUsersRoles()
     * @apiVersion 1.0.0
     * @apiGroup UsersRolesController
     * @apiName AddUsersRoles()
     * @apiParam (请求参数) {Number} id
     * @apiParam (请求参数) {Number} usersId 用户id
     * @apiParam (请求参数) {Number} rolesId 角色id
     * @apiParam (请求参数) {Object} createdTime 创建时间
     * @apiParam (请求参数) {Object} updatedTime 更新时间
     * @apiParam (请求参数) {Number} createdUserId 创建人
     * @apiParam (请求参数) {Number} updatedUserId 更新人
     * @apiParamExample 请求参数示例
     * updatedTime=null&createdUserId=8717&usersId=7822&rolesId=6747&createdTime=null&id=7294&updatedUserId=9460
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Boolean} data
     * @apiSuccessExample 响应结果示例
     * {"traceId":"mJ4O381dP","code":2249,"data":false,"success":false,"message":"8uTu7hkxr","errors":"r6sfdpS"}
     */
    @RequestMapping("/AddUsersRoles")
    public ApiResponse<Boolean> AddUsersRoles(UsersRoles req)
    {
        return ApiResponse.ok(usersRolesService.save(req));
    }

    /**
     * @api {GET} /api/v1/usersRoles/DeleteUsersRoles DeleteUsersRoles()
     * @apiVersion 1.0.0
     * @apiGroup UsersRolesController
     * @apiName DeleteUsersRoles()
     * @apiParam (请求参数) {Number} id
     * @apiParam (请求参数) {Number} usersId 用户id
     * @apiParam (请求参数) {Number} rolesId 角色id
     * @apiParam (请求参数) {Object} createdTime 创建时间
     * @apiParam (请求参数) {Object} updatedTime 更新时间
     * @apiParam (请求参数) {Number} createdUserId 创建人
     * @apiParam (请求参数) {Number} updatedUserId 更新人
     * @apiParamExample 请求参数示例
     * updatedTime=null&createdUserId=2404&usersId=693&rolesId=3383&createdTime=null&id=9269&updatedUserId=4700
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Boolean} data
     * @apiSuccessExample 响应结果示例
     * {"traceId":"WLsd","code":795,"data":false,"success":true,"message":"5LefDXwT","errors":"41zIZir8TZ"}
     */
    @RequestMapping("/DeleteUsersRoles")
    public ApiResponse<Boolean> DeleteUsersRoles(UsersRoles req)
    {
        return ApiResponse.ok(usersRolesService.removeById(req.getId()));
    }



}
